<?php
/**
 * +----------------------------------------------------------------------
 * | 九月科技-ztuc.cn
 * +----------------------------------------------------------------------
 *                      .::::.
 *                    .::::::::.            | AUTHOR: siyu
 *                    :::::::::::           | EMAIL: ztucke@ztuc.cn
 *                 ..:::::::::::'           | DATETIME: 2020/01/31
 *             '::::::::::::'
 *                .::::::::::
 *           '::::::::::::::..
 *                ..::::::::::::.
 *              ``::::::::::::::::
 *               ::::``:::::::::'        .:::.
 *              ::::'   ':::::'       .::::::::.
 *            .::::'      ::::     .:::::::'::::.
 *           .:::'       :::::  .:::::::::' ':::::.
 *          .::'        :::::.:::::::::'      ':::::.
 *         .::'         ::::::::::::::'         ``::::.
 *     ...:::           ::::::::::::'              ``::.
 *   ```` ':.          ':::::::::'                  ::::..
 *                      '.:::::'                    ':'````..
 * +----------------------------------------------------------------------
 */
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/3/14
 * Time: 17:18
 */

namespace app\lnadmin\model\admin;


use app\lnadmin\model\core\InitModel;
use think\model\concern\SoftDelete;


class Navbar extends InitModel
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    // 定义表
    protected $name = 'navbar';

    // 第一自动写入时间字段
    protected $createTime = 'create_time';
    protected $updateTime = 'update_time';

    const TYPE_INDEX = 1;   //首页
    const TYPE_HOT = 2;     // 热门
    const TYPE_RECOMMEND = 3;   // 推荐

    // 可用字段
    protected static $available = [
        'id',
        'pid',
        'type',
        'cat_name',
        'nickname',
        'column',
        'description',
        'create_time',
        'update_time',
        'weigh',
        'status',
    ];
  
    // 查询单条栏目
    public static function findNavbar($id)
    {
        $data = self::where(['id' => $id])->find();
        return $data;
    }

    /**
     * 栏目树-----后台
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author: MK
     * @Time: 2020/4/10 22:42
     */
    public static function navbar()
    {   
        return self::where(['status'=>1,'column'=>1])->field(['id','pid','cat_name as name'])->select()->toArray();// 新增编辑文章栏目
    }
}